// Copyright 2011 Google Inc. All Rights Reserved.

/**
 * @fileoverview This is the root module for the net-score egg test.
 *
 * @author gavaletz@google.com (Eric Gavaletz)
 *
 * This test is designed to run unobtrusively but to provide a visual
 * indication that a test has been run.  When the test is completed it will
 * display a link to the results so that the user can view them in more detail.
 */


goog.provide('egg');


goog.require('datastore');
goog.require('late');
goog.require('page');
goog.require('thr');
goog.require('track');


/**
 * The main entry point for a net-score egg test.
 *
 * Sets up the testing order and calls the first function in the chain of tests
 * to be run.
 */
egg.start = function() {
  page.eggSetup();
  track.trackMe(track.trackingCode);
  track.userAgent();
  late.nextFunction = thr.start;
  thr.nextFunction = datastore.postJson;
  datastore.nextFunction = egg.done;
  try {
    late.start();
  }
  catch (err) {
    datastore.logError('eggError', err);
    try {
      datastore.postJson();
    }
    catch (err) {
      datastore.logError('postJsonError', err);
    }
  }
};
//used by the closure compiler to eport this function call
goog.exportProperty(window, 'eggStart', egg.start);


/**
 * Finishes up the testing.
 *
 * The last function in the chain to be called.  Wrapps up the testing and
 * calls a method to display a link to the results.
 */
egg.done = function() {
  var url = page.resultDetailUrl + datastore.resultKey;
  page.eggLink(url, late.medRtt.toFixed(2), thr.goodput.toFixed(2));
};
